package com.cgwx.systemservice.controller;


import com.cgwx.springsecurity.entity.SysOperLog;
import com.cgwx.springsecurity.service.SysOperLogService;
import com.cgwx.commonutils.result.SysResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cgwx.springsecurity.entity.SysOperLogQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author GaoWei
 * @since 2023-10-12
 */

@Api(tags = "操作日志记录前端控制器")
@RestController
@RequestMapping("/system/sysOperLog")
@CrossOrigin
public class SysOperLogController {

    @Autowired
    private SysOperLogService sysOperLogService;

//    供其他模块远程调用
    @ApiOperation("操作日志记录")
    @PostMapping("saveSysLog")
    public SysResult saveSysLog(
            @ApiParam(name = "operLog", value = "待保存的操作日志")
            @RequestBody SysOperLog operLog) {
        sysOperLogService.saveSysLog(operLog);
        return SysResult.ok();
    }

//    供其他模块远程调用
    @ApiOperation(value = "获取分页列表")
    @GetMapping("selectPage/{page}/{limit}")
    public IPage<SysOperLog> selectPage(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable("page") Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable("limit") Long limit,

            @ApiParam(name = "sysOperLogQueryVo", value = "查询对象")
                    SysOperLogQueryVo sysOperLogQueryVo) {
        Page<SysOperLog> pageParam = new Page<>(page, limit);
        return sysOperLogService.selectPage(pageParam, sysOperLogQueryVo);
    }

//    条件分页查询操作日志
    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public SysResult index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable("page") Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable("limit") Long limit,

            @ApiParam(name = "sysOperLogQueryVo", value = "查询对象")
            SysOperLogQueryVo sysOperLogQueryVo) {
        Page<SysOperLog> pageParam = new Page<>(page, limit);
        IPage<SysOperLog> pageModel = sysOperLogService.selectPage(pageParam, sysOperLogQueryVo);
        return SysResult.ok(pageModel);
    }
}

